package com.cloudsigns.factorymanager2.produce.presenter;

import android.os.Handler;

import com.cloudsigns.factorymanager2.engineering.bean.AccountInfoBean;
import com.cloudsigns.factorymanager2.produce.iview.IGetAccountListView;
import com.cloudsigns.factorymanager2.produce.model.GetAccountListModel;
import com.cloudsigns.factorymanager2.produce.model.IGetAccountListModel;

import java.util.List;

public class GetAccountListPresenter {
    private IGetAccountListView view;
    private IGetAccountListModel model;
    private Handler handler = new Handler();

    public GetAccountListPresenter(IGetAccountListView view) {
        this.view = view;
        this.model = new GetAccountListModel();
    }

    public void getAccountList() {
        model.getAccountList(new GetAccountListModel.OnGetAccountListListener() {
            @Override
            public void successed(final List<AccountInfoBean> accountItemList) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getAccountListSuccessed(accountItemList);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void failed(final String desc) {
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.getAccountListFailed(desc);
                        view.hideLoading();
                    }
                });
            }
        });
    }
}
